package com.meilishuo.message.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.meilishuo.message.entity.common.GeneralResult;
import com.meilishuo.message.entity.common.PageForm;
import com.meilishuo.message.service.OrderDetailService;
import com.meilishuo.message.service.SessionService;
import com.meilishuo.message.service.SynOrderDetailService;
import com.meilishuo.message.util.request.OrderListRequest;

@Controller
@RequestMapping("/api")
public class OrderDetailController extends BaseController{
	
	@Autowired
	OrderDetailService orderDetailService;
	
	@Autowired
	SynOrderDetailService synOrderDetailService;
	
	@Autowired
	SessionService sessionService;
	//获得订单详情列表
	@RequestMapping(value={"/orders"},method=RequestMethod.GET)
	@ResponseBody
	public GeneralResult getList(PageForm<Object> pageForm){
		return GeneralResult.newBuilder()
				.setResult(orderDetailService.getList(pageForm)).getResponse();
	}
	
	//获得订单详情列表
	@RequestMapping(value={"/orderList"},method=RequestMethod.GET)
	@ResponseBody
	public GeneralResult put(OrderListRequest listRequest,HttpServletRequest request) throws ParseException{
		Date ctime_start= SimpleDateFormat.getDateTimeInstance().parse("2015-04-01 00:00:00");
        Date ctime_end=SimpleDateFormat.getDateInstance().parse("2015-06-12 00:00:00");
        listRequest=new OrderListRequest();
        listRequest.setCtime_start(ctime_start);
        listRequest.setCtime_end(ctime_end);
        listRequest.setPage(0);
        listRequest.setPage_size(100);
        listRequest.setStatus(0);
		synOrderDetailService.sycOrderList(listRequest, "663a61742ae4329efe5d9e05fe3e09a2"); 
		return GeneralResult.newBuilder().getResponse();
	}
	
	@RequestMapping(value={"/getCode/"},method=RequestMethod.GET)
	@ResponseBody
	public GeneralResult getCode(@RequestParam(value="code",required=false) String code){
		if (code==null) {
			return GeneralResult.newBuilder().getResponse();
		}else {
			if (sessionService.getSession(code)) {
				return GeneralResult.newBuilder().getResponse();
			}
		}
		return GeneralResult.newBuilder().getResponse();
	}
}
